package com.smartsoft.storage.action;

import javax.annotation.Resource;

import com.opensymphony.xwork2.ActionSupport;
import com.smartsoft.storage.entity.User;
import com.smartsoft.storage.service.UserService;

public class LoginAction extends ActionSupport {

    /** * serialVersionUID */
	private static final long serialVersionUID = 1L;

	@Resource
    private UserService userService;  
    private String username;  
    private String password;  

    public String getUsername() {  
        return username;  
    }  
    public void setUsername(String username) {  
        this.username = username;  
    }  
    public String getPassword() {  
        return password;  
    }  
    public void setPassword(String password) {  
        this.password = password;  
    }  

    @Override  
    public String execute() throws Exception {  
        User user = new User();  
        user.setUsername(username);  
        user.setPassword(password);  
        try {  
            userService.addUser(user);  
            //HttpServletRequest request = ServletActionContext.getRequest();  
            //request.getSession().setAttribute("username", username);  
            return "success";  
        } catch (Exception e) {  
            e.printStackTrace();  
        }  
        return "error";  
    }
}
